package com.elective.courseselect.controller;

import com.elective.courseselect.entity.CourseQuestionnaireEntity;
import com.elective.courseselect.entity.QuestionEntity;
import com.elective.courseselect.service.CourseQuestionnaireService;
import com.elective.courseselect.utils.PageUtils;
import com.elective.courseselect.utils.R;
import com.elective.status.StatusCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 课程调查问卷
 *
 * @author lee
 * @email 943204006@qq.ccom
 * @date 2021-09-04 19:22:34
 */
@RestController
@RequestMapping("courseselect/coursequestionnaire")
public class CourseQuestionnaireController {
    @Autowired
    private CourseQuestionnaireService courseQuestionnaireService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = courseQuestionnaireService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CourseQuestionnaireEntity courseQuestionnaire = courseQuestionnaireService.getById(id);

        return R.ok().put("courseQuestionnaire", courseQuestionnaire);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody CourseQuestionnaireEntity courseQuestionnaire){
		courseQuestionnaireService.save(courseQuestionnaire);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody CourseQuestionnaireEntity courseQuestionnaire){
		courseQuestionnaireService.updateById(courseQuestionnaire);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		courseQuestionnaireService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    //查询课程意愿调查问卷
    @ApiOperation("查询课程意愿调查问卷")
    @GetMapping("/searchClassQuestion/{classId}")
    public R searchClassQuestion(@PathVariable Integer classId){
        List<QuestionEntity> list = courseQuestionnaireService.searchClassQuestion(classId);
        return R.ok(StatusCode.OK,classId + "号课程，查询课程意愿调查问卷").put("list",list);
    }


    //7.3.23. 查看性格调查问卷详情
    @ApiOperation("查看性格调查问卷详情")
    @GetMapping("/searchCharacterQuestion/{questionnaireId}")
    public R searchCharacterQuestion(@PathVariable Integer questionnaireId){
        R r = courseQuestionnaireService.searchCharacterQuestion(questionnaireId);
        return r;
    }

}
